package cn.mogugo.util.tools;

import java.math.BigDecimal;
import java.util.List;


public class Random {
	
	/**
	 * 根据参数获取与参数位数相同的随机数
	 * 确保了5位数的随机数
	 * @param number
	 * @return
	 */
	public static BigDecimal getIntRandom(int num){
		BigDecimal minBd = new BigDecimal(0.1);
		BigDecimal bd = null;
		while(bd == null || bd.compareTo(minBd) == -1){
			bd = new BigDecimal(Math.random());
		}
		return bd.movePointRight(num);
	}
	
	/**
	 * 根据参数获取与参数位数相同的随机数
	 * 确保了5位数的随机数
	 * @param number
	 * @return
	 */
	public static String getStrRandom(int num){
		return Random.getIntRandom(num).toBigInteger().toString();
	}
	
	
	public static int getRandomInParam(int param){
		return ((Double)(Math.random()*param)).intValue();
	}
	
	public static void main(String[] args){
		boolean isout = true;
		while(isout){
			int a = Random.getRandomInParam(80);
			if(a < 0 || a > 80){
				System.out.println("out");
				isout = false;
			}if(a == 0 || a == 79){
				System.out.println("------------" + a);
			}else{
				System.out.println(a);
			}
		}
		
		
	}
	
	public static String getNumberRandom(){
		return (char)(Math.random ()*10+'0')+"";
	}
	
	public static String getULetterRandom(){
		return (char)(Math.random ()*26+'A')+"";
	}
	
	public static String getLetterRandom(){
		return (char)(Math.random ()*26+'a')+"";
	}
	
	public static String getLetterRandom(int num){
		String strRtn = "";
		for(int i = 0 ; i < num ; i ++ ){
			strRtn += getLetterRandom();
		}
		return strRtn;
	}

	
	
	public static Object getRandomFromList(List list){
		int size = list.size();
		return list.get(Random.getRandomInParam(size));
	}
}
